home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / RealTime Graphics ActiveX / DATA.3 / Examples / CPP / Simple / SimpleView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-16  |  5.1 KB  |  189 lines

  1. // SimpleView.cpp : implementation of the CSimpleView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Simple.h"
  6.  
  7. #include "SimpleDoc.h"
  8. #include "SimpleView.h"
  9. #include "ctwxdef.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CSimpleView
  19.  
  20. IMPLEMENT_DYNCREATE(CSimpleView, CFormView)
  21.  
  22. BEGIN_MESSAGE_MAP(CSimpleView, CFormView)
  23.     //{{AFX_MSG_MAP(CSimpleView)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard printing commands
  28.     ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  29.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  30.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CSimpleView construction/destruction
  35.  
  36. CSimpleView::CSimpleView()
  37.     : CFormView(CSimpleView::IDD)
  38. {
  39.     //{{AFX_DATA_INIT(CSimpleView)
  40.         // NOTE: the ClassWizard will add member initialization here
  41.     //}}AFX_DATA_INIT
  42.     // TODO: add construction code here
  43.  
  44. }
  45.  
  46. CSimpleView::~CSimpleView()
  47. {
  48. }
  49.  
  50. void CSimpleView::DoDataExchange(CDataExchange* pDX)
  51. {
  52.     CFormView::DoDataExchange(pDX);
  53.     //{{AFX_DATA_MAP(CSimpleView)
  54.     DDX_Control(pDX, IDC_SCROLLXCTRL1, m_RTScroll1);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BOOL CSimpleView::PreCreateWindow(CREATESTRUCT& cs)
  59. {
  60.     // TODO: Modify the Window class or styles here by modifying
  61.     //  the CREATESTRUCT cs
  62.  
  63.     return CFormView::PreCreateWindow(cs);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSimpleView printing
  68.  
  69. BOOL CSimpleView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71.     // default preparation
  72.     return DoPreparePrinting(pInfo);
  73. }
  74.  
  75. void CSimpleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77.     // TODO: add extra initialization before printing
  78. }
  79.  
  80. void CSimpleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add cleanup after printing
  83. }
  84.  
  85. void CSimpleView::OnPrint(CDC* pDC, CPrintInfo*)
  86. {
  87.     // TODO: add code to print the controls
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CSimpleView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CSimpleView::AssertValid() const
  95. {
  96.     CFormView::AssertValid();
  97. }
  98.  
  99. void CSimpleView::Dump(CDumpContext& dc) const
  100. {
  101.     CFormView::Dump(dc);
  102. }
  103.  
  104. CSimpleDoc* CSimpleView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimpleDoc)));
  107.     return (CSimpleDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CSimpleView message handlers
  113.  
  114. BEGIN_EVENTSINK_MAP(CSimpleView, CFormView)
  115.     //{{AFX_EVENTSINK_MAP(CSimpleView)
  116.     ON_EVENT(CSimpleView, IDC_SCROLLXCTRL1, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl1, VTS_NONE)
  117.     //}}AFX_EVENTSINK_MAP
  118. END_EVENTSINK_MAP()
  119.  
  120. void CSimpleView::OnInternalTimerScrollxctrl1() 
  121. {
  122.  
  123.     double rData[16];
  124.     int        i;
  125.     static double rLastData[16];
  126.     static BOOL bFirstDemoPass = FALSE;
  127.     
  128.     double rMin = min( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
  129.     double rMax = max( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
  130.     double rCenter = (rMax - rMin) /2;
  131.     double rRange = (rMin - rMax);
  132.     
  133.     for (i=0; i < m_RTScroll1.GetSDataNumGroups (0); i++)
  134.     {
  135.         if (!bFirstDemoPass)
  136.             rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
  137.         else
  138.             rData[i] = rLastData[i] + rRange * 0.2 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
  139.  
  140.         if (rData[i] > rMax)
  141.             rData[i] = rMax;
  142.         else
  143.             if (rData[i] < rMin) 
  144.                 rData[i] = rMin;
  145.         rLastData[i] = rData[i];
  146.     }
  147.  
  148.     bFirstDemoPass = TRUE; 
  149.     m_RTScroll1.UpdateDynData (0, rData);
  150.     
  151. }
  152.  
  153. void CSimpleView::BuildGraph1()
  154. {
  155.     m_RTScroll1.SetSDataEnable (0, TRUE); // enable the 1st data set
  156.     m_RTScroll1.SetSPlotType (0, SCROLLING_LINE_GRAPH);
  157.     m_RTScroll1.SetSDataNumGroups (0, 4); // four channels of data
  158.  
  159.     //axis
  160.     m_RTScroll1.SetAxisMax (X_AXIS1, 25.0); // x axis from 0 - 25
  161.     m_RTScroll1.SetAxisEnable (X_AXIS2, TRUE); //enable the second x axis
  162.     m_RTScroll1.SetAxisEnable (Y_AXIS2, TRUE); //enable the second x axis
  163.     m_RTScroll1.SetAxisMajorTickInterval (X_AXIS1, 5.0); //label every 5 units
  164.  
  165.     //alarm updating
  166.     m_RTScroll1.SetScrollAlarmMarksEnable (0, TRUE); //enable alarm marks
  167.     m_RTScroll1.SetScrollLowAlarmEnable (0, TRUE); //enable lo alarm line
  168.     m_RTScroll1.SetScrollHighAlarmEnable (0, TRUE); //enable hi alarm line
  169.     m_RTScroll1.SetScrollSetpointEnable (0, TRUE); //enable set point line
  170.  
  171.     //title
  172.     m_RTScroll1.SetTitleString (TITLE1,"Scroll Graph");  //graph title
  173.     
  174.     //window
  175.     m_RTScroll1.SetWindowBackgroundColor (C_PALEBLUE);  //background color
  176.     m_RTScroll1.SetWindowBorderStyle (RC_HIGH); 
  177.     
  178.     //use internal timer
  179.     m_RTScroll1.SetEnableInternalTimer(TRUE);
  180.     
  181. }
  182.  
  183. void CSimpleView::OnInitialUpdate() 
  184. {
  185.     CFormView::OnInitialUpdate();
  186.     
  187.     BuildGraph1();    
  188. }
  189.